package cn.wit.summit.chwan.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.adapters.FragmentPagerAdapter;
import cn.wit.summit.chwan.ui.base.BaseActivity;
import cn.wit.summit.chwan.ui.fragment.GameListFragment;
import cn.wit.summit.chwan.widgets.MyViewPager;

/**
 * Created by Alan on 2018/9/28.
 */

public class GameListActivity extends BaseActivity {

    @Bind(R.id.activityDetailTabs)
    SlidingTabLayout activityDetailTabs;
    @Bind(R.id.viewPager)
    MyViewPager viewPager;

    private String[] tabs = {"网游榜", "单机榜"};
    private List<FragmentPagerAdapter.Item> items = new ArrayList<>();
    private FragmentPagerAdapter mFragmentPagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game_list);
        ButterKnife.bind(this);

        initTabs();
    }

    private void initTabs() {
        for (int i = 0; i < tabs.length; i++) {
            Fragment fragment = GameListFragment.newInstance(i+1);
            items.add(new FragmentPagerAdapter.Item(tabs[i], fragment));
        }
        mFragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager(), items);
        viewPager.setScanScroll(true);
        viewPager.setAdapter(mFragmentPagerAdapter);
        viewPager.setCurrentItem(0);
        viewPager.setOffscreenPageLimit(tabs.length);
        activityDetailTabs.setViewPager(viewPager);
    }
}
